
#include "jellyfish.h"
#include <QRandomGenerator>

Jellyfish::Jellyfish(QGraphicsItem* parent)
    : QObject(nullptr),
    QGraphicsPixmapItem(parent)
{

    setTransformOriginPoint(boundingRect().center()); // 设置旋转中心
}



void Jellyfish::floatAnimation()
{
    // 创建上下浮动动画
    QPropertyAnimation *anim = new QPropertyAnimation(this, "y");
    anim->setDuration(2000 + QRandomGenerator::global()->bounded(1000));
    anim->setStartValue(y() - 20);
    anim->setEndValue(y() + 20);
    anim->setEasingCurve(QEasingCurve::InOutSine);
    anim->setLoopCount(-1); // 无限循环
    anim->start();
}
